<template>
	<view class="pagesItem">
		<view class="status_bar01"></view>
		<view class="header">
			<view class="more iconfont" @tap="backPage">&#xe8c8;</view>
			<view class="search">
				<view class="icon iconfont">&#xe605;</view>
				<input type="text" v-model="kw" placeholder="搜索更多商品" @confirm="search" confirm-type="search" />
			</view>
		</view>
		<view class="nav_box" id="nav_box">
			<view class="nav">
				
					<view class="menu iconfont" :class="m_index == 0 ? 'm_select':''" @tap="setContentMenu(0)">
						店长推荐
					</view>
			<view class="menu iconfont" :class="m_index ==1 ? 'm_select':''" @tap="setContentMenu(1)">
				店长礼包
			</view>
			<view class="menu iconfont" :class="m_index == 2 ? 'm_select':''" @tap="setContentMenu(2)">
				店长风采
			</view>
				<!-- <view class="menu iconfont">积分  &#xe600;</view> -->
			</view>
		</view>
		
		<view class="clear_box08" :style="{ height: descHeight + 'px' }"></view>
		<view class="list" v-if="m_index != 2">
			<view class="goods" v-for="(item,index) in dataList" :key="'g_'+index" :data-url="'/pages/goods/goods?id=' + item.goods_id" @click="gotopage">
			
				<image class="g_img" :src="item.image"></image>
				<view class="g_title">{{item.name}}</view>
				<view class="g_price">
					<view class="g_p" v-if="item.pay_type == 1">￥{{item.price}}</view>
						<view class="g_p" v-if="item.pay_type == 3">积分：{{ item.pay_znb }}</view>
					<view class="car iconfont22">&#xe600;</view>
				</view>
				
			</view>
		</view>
		<view class="list" v-if="m_index == 2">
			<view class="news" v-for="(item,index) in newList" :key="'n_'+index" :data-url="'/pages/notice/noticecontent?id='+item.id" @click="gotopage">
				<view class="n_icon iconfont">&#xe640;</view>
				<view class="n_tit" >{{item.title}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newList:[],
				flsel:0,
				marks:5,
				main_cate: [],
				j: 1,
				descHeight: 0,
				kw: '',
				cid: 0,
				by: 'views',
				page: 1,
				type: 0,
				category: [],
				dataList: [],
			filter: [{ name: '综合', by: 'views', check: true }, { name: '销量', by: 'sales', check: false }, { name: '价格', by: 'price', check: false }],
			
			
				m_index:0,
				goodsList:[
					{id:'',title:'这里是标题',price:'100.00',image:''},
					{id:'',title:'这里是标题',price:'100.00',image:''},
					{id:'',title:'这里是标题',price:'100.00',image:''}
				]
			};
		},
		onReady() {
			var that = this;
			const query = uni.createSelectorQuery().in(this);
			query
				.select('#nav_box')
				.boundingClientRect(data => {
					// console.log("得到布局位置信息" + JSON.stringify(data));
					// console.log(data.height);
					that.descHeight = data.height + 50 + uni.getSystemInfoSync().statusBarHeight;
					console.log(that.descHeight);
				})
				.exec();
		},
		onReachBottom() {
			this.loadMore();
		},
		onLoad(e) {
			let me = this;
			me.cid = e.cid || 0;
			me.kw = e.kw || '';
			me.type = e.type || 0;
			//me.marks = e.marks || 0;
			if (me.kw != '') me.cid = 0;
			// me.Net._get('filter1',{},(res)=>{
			// 			me.main_cate = res.data.main_cate;
					
			// 		console.log(res.data)
			// 	}); 
			me.loadData();
			me.Net._get('activity',{type:12},res=>{
				me.newList = res.data;
			});
		},
		methods:{
			onPullDownRefresh() {
				let me = this; // 下拉监听事件
				uni.stopPullDownRefresh();
				me.loadMore()
			},
			backPage() {
				uni.navigateBack();
			},
			setContentMenu(_index){
						let me = this;
				this.m_index = _index;
				me.page=1;
				if(_index==0){
					this.marks=5
					me.loadData();
				}
				if(_index==1){
					this.marks=6
					me.loadData();
				}
			},
			loadData() {
				let me = this;
				let page = me.page;
				let cid = me.cid;
				let by = me.by;
				let kw = me.kw;
				let type = me.type;
				let marks = me.marks;
				
				me.Net._get('filter', { kw: kw, cid: cid, by: by, page: page, type: type , marks: marks}, res => {
					let r = res.data.cate;
					r.unshift({ cid: 0, name: '全部', check: false });
					let b = [];
					r.forEach(item => {
						if (item.cid == cid) item.check = true;
						b.push(item);
					});
					me.category = b;
					me.dataList = res.data.list;
					//me.main_cate = res.data.main_cate;
					console.log(me.dataList);
				});
				me.setFilter();
			},
			gotopage(e) {
				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url: url
				});
			},
			search() {
				let me = this;
				me.cid = 0;
				me.by = 'goods_id';
				me.setCate();
				me.setFilter();
				me.page = 1;
				me.dataList = [];
				me.loadData();
			},
			loadMore() {
				let me = this;
				me.page = me.page + 1;
				me.loadDataAgain();
			},
			loadDataAgain() {
				let me = this;
				let page = me.page;
				let cid = me.cid;
				let by = me.by;
				let kw = me.kw;
				if (kw != '') cid = 0;
				let type = me.type;
				let marks = me.marks;
				me.Net._get('filter', { kw: kw, cid: cid, by: by, page: page ,type: type , marks: marks}, res => {
					let r = me.dataList;
					let g = res.data.list;
					if (g.length > 0) {
						g.forEach(item => {
							r.push(item);
						});
					}
					me.dataList = r;
				});
			},
			setCate() {
				let me = this;
				let cid = me.cid;
				let cate = me.category;
				let r = [];
				cate.forEach(item => {
					if (item.cid == cid) item.check = true;
					else item.check = false;
					r.push(item);
				});
				me.category = r;
			},
			setFilter() {
				let me = this;
				let by = me.by;
				let filter = me.filter;
				let r = [];
				filter.forEach(item => {
					if (item.by == by) item.check = true;
					else item.check = false;
					r.push(item);
				});
				me.filter = r;
			},
		}
	}
</script>

<style lang="scss">
*{
	box-sizing: border-box;
}
.pagesItem{
	width: 100%;
}
.header {
	width: 100%;
	height: 50px;
	display: flex;
	position: fixed;
	top: var(--status-bar-height);
	/* background-image: linear-gradient(#4d726f, #b4eef7); */
	background-color: #4d726f;
	z-index: 9999;
}

.header .location_box {
	height: 50px;
	width: 70px;
	display: flex;
	margin-right: 10px;
}

.header .location_box .location {
	font-size: 14px;
	color: #fff;
	line-height: 50px;
	margin-right: 5px;
	margin-left: 10px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.header .location_box .arrow {
	font-size: 10px;
	color: #666;
	line-height: 50px;
}

.header .search {
	width: calc(100% - 40px);
	height: 30px;
	margin-top: 10px;
	display: flex;
	background-color: #fff;
	border-radius: 30px;
}

.header .search .icon {
	font-size: 14px;
	color: #666;
	line-height: 30px;
	margin-left: 10px;
}

.header .search input {
	font-size: 12px;
	color: #333;
	height: 30px;
	line-height: 30px;
	margin-left: 10px;
}

.header .more {
	width: 30px;
	height: 50px;
	text-align: center;
	line-height: 50px;
	font-size: 16px;
	color: #fff;
}
.nav_box {
	width: 100%;
	background-color: #4d726f;
	position: fixed;
	top: calc(50px + var(--status-bar-height));
	z-index: 999;
}
.nav {
	width: 100%;
	display: flex;
	justify-content: center;
}
.nav .menu {
	width: 33%;
	display: flex;
	height: 45px;
	justify-content: center;
	font-size: 32rpx;
	color: #fff;
	line-height: 40px;
	box-sizing: border-box;
	border-bottom: 1px solid #f5f5f5;
	
}
.m_select{
	position: relative;
	font-size: 32rpx;
	font-weight: bold;
	&::after{
		content: '';
		position: absolute;
		width: 36%;
		min-height: 5rpx;
		background: #FFFFFF;
		bottom: 20rpx;
		left: 32%;
		border-radius: 2rpx;
	}
}
.list{
	width: 100%;
	padding: 0 30rpx 30rpx;
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	.goods{
		width: calc(50% - 10rpx);
		padding: 25rpx;
		background: #fff;
		border-radius: 15rpx;
		margin-top: 20rpx;
		.g_img{
			width: 100%;
			height: 42vw;
			border-radius: 15rpx;
		}
		.g_title{
			padding-top: 15rpx;
			font-size: 3.5vw;
			color: #232426;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 2;
			overflow: hidden;
			padding: 0 5px;
			line-height: 20px;
			font-weight: bold;
		}
		.g_price{
			width: 100%;
			padding-top: 15rpx;
			display: flex;
			align-items: center;
			.g_p{
				flex: 1;
				color: #fe4816;
				font-size: 4vw;
				font-weight: bold;
			}
			.car{
				width: 7vw;
				height: 7vw;
				border-radius: 50%;
				display: flex;
				align-items: center;
				justify-content: center;
				color: #fff;
				font-size: 4.5vw;
				background-color: #4d726f;
			}
		}
	}
	.news{
		width: 100%;
		background: #FFFFFF;
		padding: 30rpx 20rpx;
		border-radius: 15rpx;
		margin-top: 20rpx;
		display: flex;
		align-items: center;
		.n_icon{
			font-size: 70rpx;
			color: #4d726f;
		}
		.n_tit{
			padding-left: 20rpx;
			font-size: 32rpx;
			font-weight: bold;
			color: #333333;
			display: -webkit-box;
			-webkit-box-orient: vertical;
			-webkit-line-clamp: 1;
			overflow: hidden;
		}
	}
}
</style>
